﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda IEncryptionSettingsStr</summary>
    public class IEncryptionSettingsStr
    {
        public int EncryptionType; // Typ sifrovania
        public string Password;
        public bool PasswordMode;
        public string FileWithPassword;
        public string OutputPath;
        public byte[] RawPassword;

        /// <summary>Konstruktor</summary>
        public IEncryptionSettingsStr()
        {
            EncryptionType = IEncryptor.ENCRYPTION_TYPE_AES256;
            Password = ""; FileWithPassword = "";
            PasswordMode = true;
            OutputPath = "";
        }

        /// <summary>Skopirovanie obsahu objektu</summary>
        /// <param name="pValue">objekt pre skopirovanie</param>
        public void Assign(IEncryptionSettingsStr pValue)
        {
            EncryptionType = pValue.EncryptionType;
            Password = pValue.Password;
            PasswordMode = pValue.PasswordMode;
            FileWithPassword = pValue.FileWithPassword;
            if (pValue.RawPassword == null) RawPassword = null;
            else RawPassword = (byte[])pValue.RawPassword.Clone();
        }
        /// <summary>Zmena objektu pomocou formulara</summary>
        /// <returns>true / false</returns>
        public bool EditWithForm()
        {
            using (IFileExplorerForm_EditEncryptionSettings F = new IFileExplorerForm_EditEncryptionSettings())
            {
                F.Value.Assign(this);
                bool B = F.ShowDialog() == System.Windows.Forms.DialogResult.OK;
                if (B) Assign(F.Value);
                return B;
            }
        }

        /// <summary>Serializacia obsahu</summary>
        /// <returns>serializovany obsah</returns>
        public string Serialize()
        {
            using (IParamList L = new IParamList())
            {
                L.SetParam("ET", EncryptionType);
                L.SetParam("PM", PasswordMode);
                L.SetParam("PWD", Password);
                L.SetParam("FP", FileWithPassword);
                return L.Serialize(true); // Serializujem 
            }
        }
        /// <summary>Deserializacia obsahu</summary>
        /// <param name="pData">serializovany obsah</param>
        public void Deserialize(string pData)
        {
            using (IParamList L = new IParamList())
            {
                L.Deserialize(pData, true); // Deserializujem
                EncryptionType = L.GetParam("ET", EncryptionType);
                PasswordMode = L.GetParam("PM", PasswordMode);
                Password = L.GetParam("PWD", Password);
                FileWithPassword = L.GetParam("FP", FileWithPassword);
                RawPassword = null;
            }
        }
    }

    /// <summary>Trieda IFileExplorerForm_EditEncryptionSettings</summary>
    public class IFileExplorerForm_EditEncryptionSettings : IForm
    {
        public IEncryptionSettingsStr Value; // Objekt pre editaciu

        protected IGroupBox FGrp; // Controls
        protected IButton FBtn_OK;
        protected IButton FBtn_Cancel;

        protected IGroupBox FGrp1, FGrp2, FGrp3;
        protected ILabel FLabel1;
        protected IComboBox FCombo_EncryptionType;
        protected ILabel FLabel2, FLabel3;
        protected ITextBox FText_Pwd, FText_Pwd2;
        protected IRadioButton FRadio_UsePwd, FRadio_UseFile;
        protected ITextBox FText_File;
        protected IButton FBtn_CreateFile, FBtn_ChooseFile;

        /// <summary>Konstruktor</summary>
        public IFileExplorerForm_EditEncryptionSettings()
        {
            Value = new IEncryptionSettingsStr(); // Inicializacia
        }

        /// <summary>Metoda: OnCreateForm</summary>
        /// <returns>true / false</returns>
        protected override bool OnCreateForm()
        {
            if (!base.OnCreateForm()) return false; // Volam predchodcu

            // Inicializacia
            MinimizeBox = false; MaximizeBox = false; FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; ShowIcon = true; ShowInTaskbar = false; StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

            SetBounds(0, 0, 300, 420); System.Drawing.Size CS = ClientSize;
            Text = lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_1;

            // Vytvorim groupbox
            FGrp = new IGroupBox(); IControl.PlaceControl_Inside(FGrp, this, 10, 10, 10, 50);

            FGrp1 = new IGroupBox(); FGrp2 = new IGroupBox(); FGrp3 = new IGroupBox();
            FRadio_UsePwd = new IRadioButton(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_10);
            FRadio_UseFile = new IRadioButton(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_7);

            FGrp.Controls.AddRange(new System.Windows.Forms.Control[] { FGrp1, FGrp2, FGrp3, FRadio_UsePwd, FRadio_UseFile });
            IControl.PlaceControl_Inside_LeftTop_LeftTop(FGrp1, FGrp, 10, 10, FGrp.ClientSize.Width - 20, 74);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FGrp2, FGrp1, 0, 10, FGrp1.Width, 130);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FGrp3, FGrp2, 0, 10, FGrp1.Width, 86);
            IControl.PlaceControl_Outside_LeftTop_LeftTop(FRadio_UsePwd, FGrp2, 10, -1); FRadio_UsePwd.BringToFront();
            IControl.PlaceControl_Outside_LeftTop_LeftTop(FRadio_UseFile, FGrp3, 10, -1); FRadio_UseFile.BringToFront();

            FLabel1 = new ILabel(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_4);
            FCombo_EncryptionType = new IComboBox(); FCombo_EncryptionType.AddMultiItems(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_4_1, '\b', new int[] { IEncryptor.ENCRYPTION_TYPE_AES128, IEncryptor.ENCRYPTION_TYPE_AES192, IEncryptor.ENCRYPTION_TYPE_AES256, IEncryptor.ENCRYPTION_TYPE_DES, IEncryptor.ENCRYPTION_TYPE_RC2_64, IEncryptor.ENCRYPTION_TYPE_RC2_128, IEncryptor.ENCRYPTION_TYPE_TRIPLE_DES_128, IEncryptor.ENCRYPTION_TYPE_TRIPLE_DES_192 });
            FGrp1.Controls.AddRange(new System.Windows.Forms.Control[] { FLabel1, FCombo_EncryptionType });
            IControl.PlaceControl_Inside_LeftTop_LeftTop(FLabel1, FGrp1, 10, 20);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FCombo_EncryptionType, FLabel1, 4, 6, FGrp1.ClientSize.Width - 28);

            FLabel2 = new ILabel(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_5);
            FText_Pwd = new ITextBox(); FText_Pwd.PasswordChar = '*';
            FLabel3 = new ILabel(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_6);
            FText_Pwd2 = new ITextBox(); FText_Pwd2.PasswordChar = '*';
            FGrp2.Controls.AddRange(new System.Windows.Forms.Control[] { FLabel2, FText_Pwd, FLabel3, FText_Pwd2 });
            IControl.PlaceControl_Inside_LeftTop_LeftTop(FLabel2, FGrp2, 10, 30);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FText_Pwd, FLabel2, 4, 6, FGrp2.ClientSize.Width - 28);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FLabel3, FText_Pwd, -4, 10);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FText_Pwd2, FLabel3, 4, 6, FGrp2.ClientSize.Width - 28);

            FText_File = new ITextBox(); FText_File.ReadOnly = true;
            FBtn_CreateFile = new IButton(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_9, Event_BtnCreateFileClick);
            FBtn_ChooseFile = new IButton(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_8, Event_BtnChooseFileClick);
            FGrp3.Controls.AddRange(new System.Windows.Forms.Control[] { FText_File, FBtn_CreateFile, FBtn_ChooseFile });
            IControl.PlaceControl_Inside_LeftTop_LeftTop(FText_File, FGrp3, 10, 20, FGrp3.ClientSize.Width - 20);
            IControl.PlaceControl_Outside_TopRight_RightBottom(FBtn_ChooseFile, FText_File, 0, 6);
            IControl.PlaceControl_Outside_TopRight_LeftTop(FBtn_CreateFile, FBtn_ChooseFile, 0, 10);

            // Vytvorim tlacidla
            FBtn_Cancel = new IButton(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_3); IControl.PlaceControl_Outside_TopRight_RightBottom(FBtn_Cancel, FGrp, 0, 10); FBtn_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            FBtn_OK = new IButton(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_2, Event_BtnOKClick); IControl.PlaceControl_Outside_TopRight_LeftTop(FBtn_OK, FBtn_Cancel, 0, 10);

            Controls.AddRange(new System.Windows.Forms.Control[] { FGrp, FBtn_OK, FBtn_Cancel }); // Zaradim do controls

            FRadio_UseFile.CheckedChanged += (s, e) =>
            {
                UpdateFormState();
            };
            FRadio_UsePwd.CheckedChanged += (s, e) =>
            {
                UpdateFormState();
            };

            FillForm(Value);
            AcceptButton = FBtn_OK; CancelButton = FBtn_Cancel; FBtn_OK.Focus();
            return true; // Vsetko OK
        }

        /// <summary>Vyplnenie formulara</summary>
        /// <param name="pValue">objekt pre vyplnenie</param>
        protected void FillForm(IEncryptionSettingsStr pValue)
        {
            FCombo_EncryptionType.SelectedIntID = pValue.EncryptionType;
            FRadio_UseFile.Checked = !pValue.PasswordMode; FRadio_UsePwd.Checked = pValue.PasswordMode;
            FText_Pwd.Text = pValue.Password;
            FText_Pwd2.Text = pValue.Password != "" ? pValue.Password : "";
            FText_File.Text = pValue.FileWithPassword;
            UpdateFormState();
        }
        /// <summary>Nacitanie obsahu formulara</summary>
        /// <param name="Result">vysledok</param>
        protected void ReadForm(IEncryptionSettingsStr Result)
        {
            Result.EncryptionType = FCombo_EncryptionType.SelectedIntID;
            Result.PasswordMode = FRadio_UsePwd.Checked;
            if (Result.PasswordMode) Result.Password = FText_Pwd.Text;
            else Result.FileWithPassword = FText_File.Text;
        }
        /// <summary>Aktualizacia stavu formulara</summary>
        protected void UpdateFormState()
        {
            bool B = FRadio_UsePwd.Checked;
            FLabel2.Enabled = B; FText_Pwd.Enabled = B; FLabel3.Enabled = B; FText_Pwd2.Enabled = B;
            B = !B;
            FText_File.Enabled = B; FBtn_CreateFile.Enabled = FBtn_ChooseFile.Enabled = B;
        }
        /// <summary>Test validity formulara</summary>
        /// <returns>true / false</returns>
        protected bool CheckForm(IEncryptionSettingsStr Result)
        {
            if (FRadio_UsePwd.Checked) // Pouzit heslo
            {
                if (FText_Pwd.Text == "") // Prazdne heslo?
                {
                    IApp.ShowError(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_12);
                    FText_Pwd.Focus();
                    return false;
                }
                if (FText_Pwd.Text != FText_Pwd2.Text)
                {
                    IApp.ShowError(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_13);
                    FText_Pwd2.Focus();
                    return false;
                }
            }
            else // Pouzit subor
            {
                if (IFileSystem.GetObjectType(FText_File.Text) != IFileSystem.OBJECT_TYPE_FILE)
                {
                    IApp.ShowError(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_11);
                    FText_File.Focus();
                    return false;
                }
                if (!IEncryptor.IsValidPWDFile(FText_File.Text))
                {
                    IApp.ShowError(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_14);
                    FText_File.Focus();
                    return false;
                }
                try
                {
                    Result.RawPassword = System.IO.File.ReadAllBytes(FText_File.Text); // Nacitam data hesla
                }
                catch
                {
                    IApp.ShowError(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_14);
                    FText_File.Focus();
                    return false;
                }
            }
            return true; // Vsetko OK
        }

        /// <summary>Event: Click pre tlacidlo OK</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_BtnOKClick(object pSender, EventArgs e)
        {
            if (!CheckForm(Value)) return; // Skontrolujem formular
            ReadForm(Value); // Nacitam data
            DialogResult = System.Windows.Forms.DialogResult.OK; // OK
        }
        /// <summary>Event: Click pre tlacidlo 'Vytvorit subor s heslom'</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_BtnCreateFileClick(object pSender, EventArgs e)
        {
            string FN = IApp.ShowEditor_ChooseFileSave(lang.FILE_EXPLORER_TEXT_41_5_1, lang.FILE_EXPLORER_TEXT_41_5_2);
            if (string.IsNullOrEmpty(FN)) return; // Zruseny vyber?
            if (!IEncryptor.GeneratePasswordFile(FN))
            {
                IApp.ShowError(lang.FILE_EXPLORER_TEXT_41_5_3);
                return;
            }
            FText_File.Text = FN;
        }
        /// <summary>Event: Click pre tlacidlo 'Vybrat subor s heslom'</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_BtnChooseFileClick(object pSender, EventArgs e)
        {
            string FN = IApp.ShowEditor_ChooseFileLoad(lang.FILE_EXPLORER_TEXT_41_6_1, lang.FILE_EXPLORER_TEXT_41_6_2);
            if (string.IsNullOrEmpty(FN)) return; // Zruseny vyber?
            if (!IEncryptor.IsValidPWDFile(FN))
            {
                IApp.ShowError(lang.FILE_EXPLORER_TEXT_41_6_3);
                return;
            }
            FText_File.Text = FN;
        }
    }

    /// <summary>Trieda IDecryptionSettingsStr</summary>
    public class IDecryptionSettingsStr
    {
        public string Password;
        public int PasswordMode;
        public string FileWithPassword;
        public byte[] RawPassword;

        /// <summary>Destruktor</summary>
        public IDecryptionSettingsStr()
        {
            Password = "";
            PasswordMode = 0;
            FileWithPassword = "";
        }

        /// <summary>Skopirovanie obsahu objektu</summary>
        /// <param name="pValue">objekt pre skopirovanie</param>
        public void Assign(IDecryptionSettingsStr pValue)
        {
            Password = pValue.Password;
            PasswordMode = pValue.PasswordMode;
            FileWithPassword = pValue.FileWithPassword;
            if (pValue.RawPassword == null) RawPassword = null;
            else RawPassword = (byte[])pValue.RawPassword.Clone();
        }
        /// <summary>Zmena objektu pomocou formulara</summary>
        /// <returns>true / false</returns>
        public bool EditWithForm(bool pMultiFiles = false)
        {
            using (IFileExplorerForm_EditDecryptionSettings F = new IFileExplorerForm_EditDecryptionSettings())
            {
                F.Value.Assign(this); F.MultiFiles = pMultiFiles;
                bool B = F.ShowDialog() == System.Windows.Forms.DialogResult.OK;
                if (B) Assign(F.Value);
                return B;
            }
        }

        /// <summary>Serializacia obsahu</summary>
        /// <returns>serializovany obsah</returns>
        public string Serialize()
        {
            using (IParamList L = new IParamList())
            {
                L.SetParam("PM", PasswordMode);
                L.SetParam("PWD", Password);
                L.SetParam("FP", FileWithPassword);
                return L.Serialize(true); // Serializujem 
            }
        }
        /// <summary>Deserializacia obsahu</summary>
        /// <param name="pData">serializovany obsah</param>
        public void Deserialize(string pData)
        {
            using (IParamList L = new IParamList())
            {
                L.Deserialize(pData, true); // Deserializujem
                PasswordMode = L.GetParam("PM", PasswordMode);
                Password = L.GetParam("PWD", Password);
                FileWithPassword = L.GetParam("FP", FileWithPassword);
                RawPassword = null;
            }
        }
    }

    /// <summary>Trieda IFileExplorerForm_EditDecryptionSettings</summary>
    public class IFileExplorerForm_EditDecryptionSettings : IForm
    {
        public IDecryptionSettingsStr Value; // Objekt pre editaciu
        public bool MultiFiles;

        protected IGroupBox FGrp; // Controls
        protected IButton FBtn_OK;
        protected IButton FBtn_Cancel;

        protected IGroupBox FGrp2, FGrp3;
        protected ILabel FLabel2;
        protected ITextBox FText_Pwd;
        protected IRadioButton FRadio_UsePwd, FRadio_UseFile, FRadio_AskForAll;
        protected ITextBox FText_File;
        protected IButton FBtn_ChooseFile;

        /// <summary>Konstruktor</summary>
        public IFileExplorerForm_EditDecryptionSettings()
        {
            Value = new IDecryptionSettingsStr(); // Inicializacia
        }

        /// <summary>Metoda: OnCreateForm</summary>
        /// <returns>true / false</returns>
        protected override bool OnCreateForm()
        {
            if (!base.OnCreateForm()) return false; // Volam predchodcu

            // Inicializacia
            MinimizeBox = false; MaximizeBox = false; FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; ShowIcon = true; ShowInTaskbar = false; StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

            SetBounds(0, 0, 300, 330); System.Drawing.Size CS = ClientSize;
            Text = lang.FORM_EXPORT_EDIT_DECRYPTION_SETTINGS_TEXT_1;

            // Vytvorim groupbox
            FGrp = new IGroupBox(); IControl.PlaceControl_Inside(FGrp, this, 10, 10, 10, 50);

            FGrp2 = new IGroupBox(); FGrp3 = new IGroupBox();
            FRadio_UsePwd = new IRadioButton(MultiFiles ? lang.FORM_EXPORT_EDIT_DECRYPTION_SETTINGS_TEXT_8 : lang.FORM_EXPORT_EDIT_DECRYPTION_SETTINGS_TEXT_7);
            FRadio_UseFile = new IRadioButton(lang.FORM_EXPORT_EDIT_DECRYPTION_SETTINGS_TEXT_6);
            if (MultiFiles) FRadio_AskForAll = new IRadioButton(lang.FORM_EXPORT_EDIT_DECRYPTION_SETTINGS_TEXT_9);

            if (MultiFiles) FGrp.Controls.AddRange(new System.Windows.Forms.Control[] { FGrp2, FGrp3, FRadio_UsePwd, FRadio_UseFile, FRadio_AskForAll });
            else FGrp.Controls.AddRange(new System.Windows.Forms.Control[] { FGrp2, FGrp3, FRadio_UsePwd, FRadio_UseFile });
            IControl.PlaceControl_Inside_LeftTop_LeftTop(FGrp2, FGrp, 10, 20, FGrp.ClientSize.Width - 20, 86);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FGrp3, FGrp2, 0, 10, FGrp2.Width, 86);
            IControl.PlaceControl_Outside_LeftTop_LeftTop(FRadio_UsePwd, FGrp2, 10, -1); FRadio_UsePwd.BringToFront();
            IControl.PlaceControl_Outside_LeftTop_LeftTop(FRadio_UseFile, FGrp3, 10, -1); FRadio_UseFile.BringToFront();
            if (MultiFiles) IControl.PlaceControl_Outside_LeftTop_LeftBottom(FRadio_AskForAll, FGrp3, 10, 8);

            FLabel2 = new ILabel(lang.FORM_EXPORT_EDIT_DECRYPTION_SETTINGS_TEXT_4);
            FText_Pwd = new ITextBox(); FText_Pwd.PasswordChar = '*';
            FGrp2.Controls.AddRange(new System.Windows.Forms.Control[] { FLabel2, FText_Pwd });
            IControl.PlaceControl_Inside_LeftTop_LeftTop(FLabel2, FGrp2, 10, 30);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FText_Pwd, FLabel2, 4, 6, FGrp2.ClientSize.Width - 28);

            FText_File = new ITextBox(); FText_File.ReadOnly = true;
            FBtn_ChooseFile = new IButton(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_7, Event_BtnChooseFileClick);
            FGrp3.Controls.AddRange(new System.Windows.Forms.Control[] { FText_File, FBtn_ChooseFile });
            IControl.PlaceControl_Inside_LeftTop_LeftTop(FText_File, FGrp3, 10, 20, FGrp3.ClientSize.Width - 20);
            IControl.PlaceControl_Outside_TopRight_RightBottom(FBtn_ChooseFile, FText_File, 0, 6);

            // Vytvorim tlacidla
            FBtn_Cancel = new IButton(lang.FORM_EXPORT_EDIT_DECRYPTION_SETTINGS_TEXT_3); IControl.PlaceControl_Outside_TopRight_RightBottom(FBtn_Cancel, FGrp, 0, 10); FBtn_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            FBtn_OK = new IButton(lang.FORM_EXPORT_EDIT_DECRYPTION_SETTINGS_TEXT_2, Event_BtnOKClick); IControl.PlaceControl_Outside_TopRight_LeftTop(FBtn_OK, FBtn_Cancel, 0, 10);

            Controls.AddRange(new System.Windows.Forms.Control[] { FGrp, FBtn_OK, FBtn_Cancel }); // Zaradim do controls

            FRadio_UseFile.CheckedChanged += (s, e) =>
            {
                UpdateFormState();
            };
            FRadio_UsePwd.CheckedChanged += (s, e) =>
            {
                UpdateFormState();
            };
            if (FRadio_AskForAll != null) FRadio_AskForAll.CheckedChanged += (s, e) =>
            {
                UpdateFormState();
            };

            FillForm(Value);
            AcceptButton = FBtn_OK; CancelButton = FBtn_Cancel; FBtn_OK.Focus();
            return true; // Vsetko OK
        }

        /// <summary>Vyplnenie formulara</summary>
        /// <param name="pValue">objekt pre vyplnenie</param>
        protected void FillForm(IDecryptionSettingsStr pValue)
        {
            FRadio_UseFile.Checked = pValue.PasswordMode == 1; FRadio_UsePwd.Checked = pValue.PasswordMode == 0;
            if (FRadio_AskForAll != null) FRadio_AskForAll.Checked = pValue.PasswordMode == 2;
            FText_Pwd.Text = pValue.Password;
            FText_File.Text = pValue.FileWithPassword;
            UpdateFormState();
        }
        /// <summary>Nacitanie obsahu formulara</summary>
        /// <param name="Result">vysledok</param>
        protected void ReadForm(IDecryptionSettingsStr Result)
        {
            if (FRadio_UsePwd.Checked) Result.PasswordMode = 0;
            if (FRadio_UseFile.Checked) Result.PasswordMode = 1;
            if ((FRadio_AskForAll != null) && (FRadio_AskForAll.Checked)) Result.PasswordMode = 2;
            if (Result.PasswordMode == 0) Result.Password = FText_Pwd.Text;
            if (Result.PasswordMode == 1) Result.FileWithPassword = FText_File.Text;
        }
        /// <summary>Aktualizacia stavu formulara</summary>
        protected void UpdateFormState()
        {
            FLabel2.Enabled = FRadio_UsePwd.Checked; FText_Pwd.Enabled = FRadio_UsePwd.Checked;
            FText_File.Enabled = FRadio_UseFile.Checked; FBtn_ChooseFile.Enabled = FRadio_UseFile.Checked;
        }
        /// <summary>Test validity formulara</summary>
        /// <returns>true / false</returns>
        protected bool CheckForm(IDecryptionSettingsStr Result)
        {
            if (FRadio_UsePwd.Checked) // Pouzit heslo
            {
                if (FText_Pwd.Text == "") // Prazdne heslo?
                {
                    IApp.ShowError(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_11);
                    FText_Pwd.Focus();
                    return false;
                }
            }
            if (FRadio_UseFile.Checked) // Pouzit subor
            {
                if (IFileSystem.GetObjectType(FText_File.Text) != IFileSystem.OBJECT_TYPE_FILE)
                {
                    IApp.ShowError(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_10);
                    FText_File.Focus();
                    return false;
                }
                if (!IEncryptor.IsValidPWDFile(FText_File.Text))
                {
                    IApp.ShowError(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_14);
                    FText_File.Focus();
                    return false;
                }
                try
                {
                    Result.RawPassword = System.IO.File.ReadAllBytes(FText_File.Text); // Nacitam data hesla
                }
                catch
                {
                    IApp.ShowError(lang.FORM_EXPORT_EDIT_ENCRYPTION_SETTINGS_TEXT_14);
                    FText_File.Focus();
                    return false;
                }
            }
            return true; // Vsetko OK
        }

        /// <summary>Event: Click pre tlacidlo OK</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_BtnOKClick(object pSender, EventArgs e)
        {
            if (!CheckForm(Value)) return; // Skontrolujem formular
            ReadForm(Value); // Nacitam data
            DialogResult = System.Windows.Forms.DialogResult.OK; // OK
        }
        /// <summary>Event: Click pre tlacidlo 'Vybrat subor s heslom'</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_BtnChooseFileClick(object pSender, EventArgs e)
        {
            string FN = IApp.ShowEditor_ChooseFileLoad(lang.FILE_EXPLORER_TEXT_41_6_1, lang.FILE_EXPLORER_TEXT_41_6_2);
            if (string.IsNullOrEmpty(FN)) return; // Zruseny vyber?
            if (!IEncryptor.IsValidPWDFile(FN))
            {
                IApp.ShowError(lang.FILE_EXPLORER_TEXT_41_6_3);
                return;
            }
            FText_File.Text = FN;
        }
    }
}
